<%--
  Created by IntelliJ IDEA.
  User: chenxiaokang
  Date: 2017/9/12
  Time: 下午7:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%request.setCharacterEncoding("utf-8");%>
<html>
<head>
    <title>Title</title>
    <meta http-equiv="content-type"content="text/html;charset=utf-8">
    <style type="text/css">
        table,th,td{
            border: 1px solid black;
            border-collapse: collapse;
        }
        input{
            border: 1px solid black;
        }
        input[type='text']{
            width: 200px;
        }
    </style>
    <script src="${pageContext.request.contextPath}/js/jQuery-3.0.0.js"></script>
    <script type="application/javascript">
        $(document).ready(function () {
            $("#queryBtn").click(function () {
               $("#form1").submit();
            });

            $("#insertBtn").click(function () {
                window.location.href="./productAdd.jsp";
            })

            $("#updateBtn").click(function () {
                var $trs = $("#tab tr");
                var prodId = null;
                for(var i = 1;i < $trs.length;i++){
                    var box = $trs.get(i).children[0].children[0];
                    if(box.checked()){
                        prodId = box.value;
                        break;
                    }
                }
                if(prodId == null){
                    alert("请选择一条记录进行修改!");
                }else{
                    window.location.href="./update.action?prodId="+prodId;
                }
            })
        });
    </script>
</head>
<body>
    <form action="./list.action" method="post" id="form1" accept-charset="UTF-8">
        <table width="800px" cellpadding="0" cellspacing="0" style="border: 0px;">
            <tr style="border: 0px;">
                <td style="border: 0px; text-align: left">
                    商品名称：<input type="text" name="pname" id="pname" value="${sessionScope.queryState.pname}"/>
                    商品编码：<input type="text" name="pcode" id="pcode" value="${sessionScope.queryState.pcode}" />
                    <input type="button" value="查询" id="queryBtn">
                    <input type="button" value="新增" id="insertBtn">
                    <input type="button" value="修改" id="updateBtn">
                    <input type="button" value="删除" id="deleteBtn">
                    <input type="button" value="明细" id="detailBtn">
                </td>
            </tr>
        </table>
    </form>
    <table width="800px" cellpadding="0" cellspacing="0" border="1px" id="tab">
        <tr>
            <th width="20px"></th>
            <th width="60px">序号</th>
            <th width="80px">商品名称</th>
            <th width="80px">商品编码</th>
            <th width="80px">商品价格</th>
            <th width="80px">商品分类</th>
            <th width="100px">生产厂家</th>
            <th>商品描述</th>
        </tr>
        <c:forEach items="${requestScope.productList}" var="prod" varStatus="status">
            <tr>
                <td align="center"><input type="checkbox" name="id" value="${prod.id}"></td>
                <td>${status.count}</td>
                <td>${prod.pname}</td>
                <td>${prod.pcode}</td>
                <td>${prod.price}</td>
                <td>${prod.ptype}</td>
                <td>${prod.pfac}</td>
                <td>${prod.desc}</td>
            </tr>
        </c:forEach>
    </table>
</body>
</html>
